/* eslint-disable jsdoc/check-tag-names */
'use strict';

const Controller = require('egg').Controller;

class AboutUsController extends Controller {
  /**
 *
 * @api {POST} /api/aboutUs/create 创建关于我们
 * @apiName 创建关于我们
 * @apiGroup 关于我们模块
 * @apiVersion  1.0.0
 *
 *
 * @apiParam  {String} culture 公司文化
 * @apiParam  {String} purpose 公司宗旨
 * @apiParam  {String} address 公司地址
 * @apiParam  {String} contact 联系方式
 * @apiParam  {String} development 发展历程
 *
 *
 * @apiParamExample  {type} Request-Example:
        {
            "culture":"公司文化",
            "purpose":"公司宗旨",
            "address":"公司地址",
            "contact":"联系方式",
            "development":"发展历程"
        }
 *
 *
 * @apiSuccessExample {type} Success-Response:
        {
            "code": 200,
            "msg": "成功操作",
            "data": {
                "id": 1,
                "culture": "公司文化",
                "purpose": "公司宗旨",
                "address": "公司地址",
                "contact": "联系方式",
                "development": "发展历程",
                "projectId": 1,
                "updatedAt": "2021-11-24T06:58:01.190Z",
                "createdAt": "2021-11-24T06:58:01.190Z"
            }
        }
 *
 *
 */
  async create() {
    const { app, ctx, service } = this;
    const checkRes = new ctx.helper.checkData(
      this,
      'culture',
      'purpose',
      'address',
      'contact',
      'development'
    ).checkDataRes;

    try {
      if (checkRes) {
        const res = await service.web.aboutUs.create();
        return ctx.helper.successModule(res);
      }
    } catch (error) {
      console.log(error);
      return ctx.helper.errorModule(error);
    }
  }

  /**
     *
     * @api {DELETE} /api/aboutUs/delete 删除关于我们
     * @apiName 删除关于我们
     * @apiGroup 关于我们模块
     * @apiVersion  1.0.0
     *
     *
     * @apiParam  {Number} id 关于我们id
     *
     *
     * @apiParamExample  {type} Request-Example:
        {
            "id":1
        }
     *
     *
     * @apiSuccessExample {type} Success-Response:
        {
            "code": 200,
            "msg": "删除成功",
            "data": []
        }
     *
     *
     */
  async delete() {
    const { ctx, service } = this;

    try {
      const res = await service.web.aboutUs.delete();
      if (res == 'id不存在,删除失败') {
        return ctx.helper.errorModule(res);
      }
      return ctx.helper.successModule(res);
    } catch (error) {
      console.log(error);
      return ctx.helper.errorModule(error);
    }
  }

  /**
    *
    * @api {PUT} /api/aboutUs/update 修改关于我们
    * @apiName 修改关于我们
    * @apiGroup 关于我们模块
    * @apiVersion  1.0.0
    *
    * @apiParam  {Number} id 关于我们
    * @apiParam  {String} culture 公司文化
    * @apiParam  {String} purpose 公司宗旨
    * @apiParam  {String} address 公司地址
    * @apiParam  {String} contact 联系方式
    * @apiParam  {String} development 发展历程
    *
    *
    * @apiParamExample  {type} Request-Example:
        {
            "id":2,
            "culture":"公司文化22",
            "purpose":"公司宗旨22",
            "address":"公司地址22",
            "contact":"联系方式22",
            "development":"发展历程22"
        }
    *
    *
    * @apiSuccessExample {type} Success-Response:
       {
           "code": 200,
           "msg": "修改成功",
           "data": []
       }
    *
    *
    */
  async update() {
    const { app, ctx, service } = this;
    const checkRes = new ctx.helper.checkData(
      this,
      'id',
      'culture',
      'purpose',
      'address',
      'contact',
      'development'
    ).checkDataRes;

    try {
      if (checkRes) {
        const res = await service.web.aboutUs.update();
        if (res == 'id不存在,修改失败') {
          return ctx.helper.errorModule(res);
        }
        return ctx.helper.successModule(res);
      }
    } catch (error) {
      console.log(error);
      return ctx.helper.errorModule('操作失败');
    }
  }

  /**
     *
     * @api {GET} /api/aboutUs/getAll?limit=10&offset=0 获取所有关于我们
     * @apiName 获取所有关于我们
     * @apiGroup 关于我们模块
     * @apiVersion  1.0.0
     *
     *
     * @apiParam  {Number} limit 关于我们返回数
     * @apiParam  {Number} offset 关于我们偏移数
     *
     *
     * @apiSuccessExample {type} Success-Response:
        {
            "code": 200,
            "msg": "成功操作",
            "data": {
                "count": 1, //总数
                "rows": [
                    {
                        "id": 2,    //关于我们id
                        "culture": "公司文化",
                        "purpose": "公司宗旨",
                        "address": "公司地址",
                        "contact": "联系方式",
                        "development": "发展历程",
                        "projectId": 1,
                        "createdAt": "2021-11-24T07:06:17.000Z",
                        "updatedAt": "2021-11-24T07:11:13.000Z"
                    }
                ],
                "projectName": "官网项目"
            }
        }
     *
     *
     */
  async getAll() {
    const { ctx, service } = this;
    try {
      const res = await service.web.aboutUs.getAll();
      return ctx.helper.successModule(res);
    } catch (error) {
      console.log(error);
      return ctx.helper.errorModule('操作失败');
    }
  }

  /**
 *
 * @api {GET} /api/aboutUs/getById?id=2 根据id查找关于我们
 * @apiName 根据id查找关于我们
 * @apiGroup 关于我们模块
 * @apiVersion  1.0.0
 *
 *
 * @apiParam  {Number} id 关于我们id
 *
 *
 * @apiSuccessExample {type} Success-Response:
        {
            "code": 200,
            "msg": "成功操作",
            "data": {
                "id": 2,
                "culture": "公司文化",
                "purpose": "公司宗旨",
                "address": "公司地址",
                "contact": "联系方式",
                "development": "发展历程",
                "projectId": 1,
                "createdAt": "2021-11-24T07:06:17.000Z",
                "updatedAt": "2021-11-24T07:11:13.000Z",
                "projectName": "官网项目"
            }
        }
 *
 *
 */
  async getById() {
    const { ctx, service } = this;
    const checkRes = new ctx.helper.checkData(this, 'id').checkDataRes;

    // 如果有缺少参数
    if (checkRes) {
      const res = await service.web.aboutUs.getById();

      return ctx.helper.successModule(res);
    }
  }
}
module.exports = AboutUsController;
